<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <#include "/back/common.html">
    <script type="text/javascript" src="/back/edit/wangEditor.min.js"></script>
    <!--<link rel="stylesheet" href="/back/layui/css/layui.css">-->
    <!--<link rel="stylesheet" href="/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">-->
    <!--<script src="/back/js/jquery.min.js"></script>
    <script src="/back/layui/layui.js"></script>-->
    <!--<script type="text/javascript" src="/zTree/js/jquery.ztree.all.js"></script>-->
    <!--<script type="text/javascript" src="/js/myTree.js"></script>-->
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>文章详情</legend>
</fieldset>

<form class="layui-form" id="userForm">
    <input type="hidden" id="pk" name="pk" value="${mv.pk}">
    <div class="layui-form-item">
        <label class="layui-form-label"><font color="red">※</font>文章类型</label>
        <div class="layui-input-inline">
            <select class="layui-select" id="articleType" name="articleType"
                    lay-search="" lay-verify="notNull" lay-filter="articleType">
                <option value="-1" selected="selected">-------请选择--------</option>
                <option value="1">芯佑电商</option>
                <option value="2">支付方式</option>
                <option value="3">网站帮助</option>
                <option value="4">其他</option>
            </select>
            <script>
                $("#articleType").val("${mv.article_type!-1}")
            </script>
        </div>
        <label class="layui-form-label"><font color="red">※</font>文章名称</label>
        <div class="layui-input-inline">
            <input type="text" name="articleName" id="articleName" value="${mv.article_name}" lay-verify="notNull" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">小标题</label>
        <div class="layui-input-block">
            <input type="text" name="articleTitle" id="articleTitle" value="${mv.article_title}" lay-ignore="true" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <input type="text" name="articleDesc" id="articleDesc" value="${mv.article_desc}" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="text-align: center">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="demo1">立即提交</button>
            <!--<button class="layui-btn layui-btn-primary layui-btn-radius" type="reset">重置</button>-->
        </div>
    </div>

    <div id="showAnotherPeace" style="display:none;">
        ${mv.article_content}
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章内容</label>
        <div class="layui-input-block">
            <div id="editor"></div>
        </div>
    </div>
    <input type="hidden" id="articleContent" name="articleContent"><!--富文本信息影藏域-->
</form>
<script>
    //富文本
    var editor = null;
    $(function() {
        var E = window.wangEditor;
        editor = new E('#editor');
        editor.customConfig.uploadImgServer = '/aliOSS/fileUpload?type=文章内容富文本图片文件夹'; // 上传图片到阿里云服务器
        editor.customConfig.uploadFileName = 'file';
        editor.customConfig.zIndex = 100;
        editor.customConfig.uploadImgHooks = {
            customInsert : function(insertImg, result, editor) {
                var url = "//"+result.data[0].path;
                insertImg(url);
            }
        };
        editor.create()

        var ss = $("#showAnotherPeace").html();
        if (ss != null && ss != '' && ss != 'undefiend') {
            editor.txt.html(ss);
        }
    });
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#birthday'
        });


        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            },
            notNull: function (value) {
                if (value.length <= 0) {
                    return '信息必填';
                }
            }
            , password: [
                /^[\w_-]{6,16}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , email: [
                /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , phone: [
                /^[1][2,3,4,5,6,7,8,9][0-9]{9}$/
                , '手机号码格式异常'
            ]
            , account: [
                /^[A-Za-z0-9]{4,16}$/
                , '请输入4位以上的英文或数字组合'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            layui.use(['jquery'], function () {
                var $ = jQuery = layui.$;
                var postUrl = "/article/saveOrUpdate";
                var str = editor.txt.html();
                $("#articleContent").val(str);
                $.ajax({
                    url: postUrl,
                    type: 'post',
                    data: $("#userForm").serialize(),
                    success: function (resp) {
                        layer.msg(resp.message);
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.initTable();//刷新表格数据
                    },
                    error: function (resp) {
                        layer.msg(resp.message);
                    }
                });
            });
            return false;
        });
    });
</script>

</body>
</html>